package cn.buk.tms.dto.request;

import cn.buk.common.util.DateUtil;
import cn.buk.tms.common.dto.hotel.BaseHotelOrderDto;
import cn.buk.tms.hotel.dto.HotelOrderPassengerDto;
import cn.buk.tms.hotel.dto.HotelOrderPriceDto;
import com.fasterxml.jackson.annotation.JsonFormat;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 机票订单创建请求DTO
 */
public class HotelOrderRequestDto extends BaseHotelOrderDto {

  /**
   * 本地酒店系统中的酒店id
   */
  private int hotelId;

  /**
   * 酒店名称
   */
  @NotNull
  @Size(min = 2, max = 100)
  private String hotelName;

  /**
   * 本地酒店系统中的售卖房型id
   */
  private int roomId;

  /**
   * 房型
   */
  @NotNull
  @Size(min = 1, max = 150)
  private String roomType;

  /**
   * 入住人信息
   */
  @NotNull
  @Size(min = 1, max = 1000)
  private List<HotelOrderPassengerDto> passengers = new ArrayList<>();

  /**
   * 入住人姓名，以前的方式，多个入住人姓名用分号隔开
   */
  private String passengerName;

  /**
   * 入住人数
   */
  private int psgCount;

  /**
   * 房间数
   */
  @Min(1)
  private int roomCount;

  /**
   * 入住日期
   */
  @NotNull
  @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
  private Date checkInDate;

  /**
   * 离店日期
   */
  @NotNull
  @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
  private Date checkOutDate;

  /**
   * 价格/间夜
   */
  private double price;

  /**
   * 底价/间夜
   */
  private Double bottomPrice;

  /**
   * 服务费
   */
  private double serviceCharge;

  /**
   * 间夜数(房间数*天数）
   */
  @NotNull
  @Min(1)
  private Integer count;


  /**
   * 实收客户总额
   */
  private Double totalAmount;

  /**
   * 总成本
   */
  private Double totalCost;

  /**
   * 利润
   */
  private Double profit;

  private String remark;

  /**
   * 供应商ID
   */
  private int supplierId;

  /**
   * 供应商名称
   */
  private String supplierName;

  /**
   * 付款方式ID
   */
  private int paymentMethodId;

  /**
   * 付款方式名称
   */
  private String paymentMethodName;

  /**
   * 上级订单号
   */
  private String parentOrderNo;

  /**
   * 似乎在酒店订单中没有用上 yfdai 2021-10-10
   * 收款备注：客户付款的具体途径
   */
  private String payRemark;

  /**
   * 最晚到店时间
   */
  private String lastArriveTime;

  /**
   * 联系人
   */
  private String linkman;

  /**
   * 联系电话
   */
  private String contactPhone;

  /**
   * 每日价格
   */
  @NotNull
  @Size(min = 0, max = 1000)
  private List<HotelOrderPriceDto> prices = new ArrayList<>();


  /**
   * 计算价格
   */
  public void calc() {
    final int days = DateUtil.getPastDays(this.checkOutDate, this.checkInDate);
    this.count = days * this.roomCount;
    this.totalAmount = this.count * this.price + this.serviceCharge;
    this.totalCost = this.count * this.bottomPrice;
    this.profit = this.totalAmount - this.totalCost;
  }

  public void processPassengerInfo() {
    String psgNames = null;
    for(HotelOrderPassengerDto psg: this.getPassengers()) {
      if (psgNames == null) {
        psgNames = psg.getName();
      } else {
        psgNames += "," + psg.getName();
      }
    }

    if (psgNames != null) {
      if (psgNames.length() > 50) {
        psgNames = psgNames.substring(0, 40);
      }

      this.passengerName = psgNames;
      this.psgCount = this.getPassengers().size();
    }
  }


  public String getHotelName() {
    return hotelName;
  }

  public void setHotelName(String hotelName) {
    this.hotelName = hotelName;
  }

  public String getRoomType() {
    return roomType;
  }

  public void setRoomType(String roomType) {
    this.roomType = roomType;
  }

  public int getRoomCount() {
    return roomCount;
  }

  public void setRoomCount(int roomCount) {
    this.roomCount = roomCount;
  }

  public Date getCheckInDate() {
    return checkInDate;
  }

  public void setCheckInDate(Date checkInDate) {
    this.checkInDate = checkInDate;
  }

  public Date getCheckOutDate() {
    return checkOutDate;
  }

  public void setCheckOutDate(Date checkOutDate) {
    this.checkOutDate = checkOutDate;
  }

  public double getPrice() {
    return price;
  }

  public void setPrice(double price) {
    this.price = price;
  }

  public Double getBottomPrice() {
    return bottomPrice;
  }

  public void setBottomPrice(Double bottomPrice) {
    this.bottomPrice = bottomPrice;
  }

  public double getServiceCharge() {
    return serviceCharge;
  }

  public void setServiceCharge(double serviceCharge) {
    this.serviceCharge = serviceCharge;
  }

  public Integer getCount() {
    return count;
  }

  public void setCount(Integer count) {
    this.count = count;
  }

  public String getRemark() {
    return remark;
  }

  public void setRemark(String remark) {
    this.remark = remark;
  }

  public int getSupplierId() {
    return supplierId;
  }

  public void setSupplierId(int supplierId) {
    this.supplierId = supplierId;
  }

  public int getPaymentMethodId() {
    return paymentMethodId;
  }

  public void setPaymentMethodId(int paymentMethodId) {
    this.paymentMethodId = paymentMethodId;
  }

  public Double getTotalAmount() {
    return totalAmount;
  }

  public void setTotalAmount(Double totalAmount) {
    this.totalAmount = totalAmount;
  }

  public Double getTotalCost() {
    return totalCost;
  }

  public void setTotalCost(Double totalCost) {
    this.totalCost = totalCost;
  }

  public Double getProfit() {
    return profit;
  }

  public void setProfit(Double profit) {
    this.profit = profit;
  }

  public List<HotelOrderPassengerDto> getPassengers() {
    return passengers;
  }

  public void setPassengers(List<HotelOrderPassengerDto> passengers) {
    this.passengers = passengers;
  }

  public String getParentOrderNo() {
    return parentOrderNo;
  }

  public void setParentOrderNo(String parentOrderNo) {
    this.parentOrderNo = parentOrderNo;
  }

  public int getHotelId() {
    return hotelId;
  }

  public void setHotelId(int hotelId) {
    this.hotelId = hotelId;
  }

  public int getRoomId() {
    return roomId;
  }

  public void setRoomId(int roomId) {
    this.roomId = roomId;
  }

  public String getPayRemark() {
    return payRemark;
  }

  public void setPayRemark(String payRemark) {
    this.payRemark = payRemark;
  }

  public String getLastArriveTime() {
    return lastArriveTime;
  }

  public void setLastArriveTime(String lastArriveTime) {
    this.lastArriveTime = lastArriveTime;
  }

  public String getLinkman() {
    return linkman;
  }

  public void setLinkman(String linkman) {
    this.linkman = linkman;
  }

  public String getContactPhone() {
    return contactPhone;
  }

  public void setContactPhone(String contactPhone) {
    this.contactPhone = contactPhone;
  }

  public List<HotelOrderPriceDto> getPrices() {
    return prices;
  }

  public void setPrices(List<HotelOrderPriceDto> prices) {
    this.prices = prices;
  }

  public int getPsgCount() {
    return psgCount;
  }

  public void setPsgCount(int psgCount) {
    this.psgCount = psgCount;
  }

  public String getPassengerName() {
    return passengerName;
  }

  public void setPassengerName(String passengerName) {
    this.passengerName = passengerName;
  }

  public String getSupplierName() {
    return supplierName;
  }

  public void setSupplierName(String supplierName) {
    this.supplierName = supplierName;
  }

  public String getPaymentMethodName() {
    return paymentMethodName;
  }

  public void setPaymentMethodName(String paymentMethodName) {
    this.paymentMethodName = paymentMethodName;
  }
}
